#ifndef LIBCO_PROCESSOR_H
#define LIBCO_PROCESSOR_H

#include "concurrent.hpp"
#include "singleton.hpp"

namespace libco {

/**
 * @brief 调度器
 * 
 * @note 协程需要和调度器绑定才能运行，一个线程对应一个调度器
 */
class Processor{
    
friend class Monitor;

public:
    using Task = Coroutine::ptr;

private:
    /// 协程本地任务队列,继承Conqueue
    TaskQueue *m_local_tasks;

    /// 调度协程
    Coroutine::ptr m_co;
    /// 调度器id 
    uint64_t m_id;
    /// 调度器状态
    bool m_stopped;
public:
    Processor();
    ~Processor();

    static Processor* GetThis();

    void add_task(Task);
    void add_task(std::function<void()>);


    size_t pop_task_n(std::vector<Task>&, size_t n);
    size_t push_task_n(std::vector<Task>&, size_t n);
    size_t tasks();
};

} // namespace libco


#endif